home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue63 / Clinic / TestComp.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-09-08  |  1.3 KB  |  57 lines

  1. unit TestComp;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes;
  7.  
  8. type
  9.   TTestRange = 0..2;
  10.  
  11. const
  12.   trZero = TTestRange(0);
  13.   trOne  = TTestRange(1);
  14.   trTwo  = TTestRange(2);
  15.  
  16. type
  17.   TTestComponent = class(TComponent)
  18.   private
  19.     FTest: TTestRange;
  20.   published
  21.     property Test: TTestRange read FTest write FTest default trZero;
  22.   end;
  23.  
  24. function IdentToTestValue(const Ident: String; var TestValue: Integer): Boolean;
  25. function TestValueToIdent(TestValue: Integer; var Ident: String): Boolean;
  26. procedure GetTestRangeValues(Proc: TGetStrProc);
  27.  
  28. implementation
  29.  
  30. const
  31.   TestValues: array[TTestRange] of TIdentMapEntry = (
  32.     (Value: trZero; Name: 'trZero'),
  33.     (Value: trOne;  Name: 'trOne'),
  34.     (Value: trTwo;  Name: 'trTwo'));
  35.  
  36. function IdentToTestValue(const Ident: String; var TestValue: Integer): Boolean;
  37. begin
  38.   Result := IdentToInt(Ident, TestValue, TestValues);
  39. end;
  40.  
  41. function TestValueToIdent(TestValue: Integer; var Ident: String): Boolean;
  42. begin
  43.   Result := IntToIdent(TestValue, Ident, TestValues);
  44. end;
  45.  
  46. procedure GetTestRangeValues(Proc: TGetStrProc);
  47. var
  48.   I: Integer;
  49. begin
  50.   for I := Low(TestValues) to High(TestValues) do
  51.     Proc(TestValues[I].Name);
  52. end;
  53.  
  54. initialization
  55.   RegisterIntegerConsts(TypeInfo(TTestRange), IdentToTestValue, TestValueToIdent)
  56. end.
  57.